#include <cctype>
#include <cstdio>
const int N = 100005;
int n, rt;
long long ans;
int e_cnt, heads[N];
struct Edge {
	int v, nxt, w;
} e[N << 1];
inline void add(int u, int v, int w) {
	e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}
int siz[N], lea[N], deg[N];
inline int read() {
	int x = 0, ch = getchar();
	bool f = false;
	while (!isdigit(ch)) {
		if (ch == '-') f = true;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return f ? -x : x;
}
void dfs(int x, int fa) {
	siz[x] = 1;
	int cnt = 0;
	for (int i = heads[x]; i; i = e[i].nxt) {
		++cnt;
		int v = e[i].v;
		if (v == fa) continue;
		dfs(v, x);
		siz[x] += siz[v];
		lea[x] += lea[v];
	}
	if (cnt == 1) lea[x] = 1;
}
void dfs2(int x, int fa) {
	for (int i = heads[x]; i; i = e[i].nxt) {
		int v = e[i].v;
		if (v == fa) continue;
		dfs2(v, x);
		ans += 1ll * (n - siz[v]) * lea[v] * e[i].w + 1ll * e[i].w * siz[v] * (lea[rt] - lea[v]);
	}
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
	freopen("sign.in", "r", stdin);
	freopen("sign.out", "w", stdout);
#endif
#endif

	n = read();
	int u, v, w;
	for (int i = 1; i < n; ++i) {
		u = read(), v = read(), w = read();
		add(u, v, w);
		add(v, u, w);
		++deg[u], ++deg[v];
	}
	if (n == 2) {
		printf("%d", w << 1);
		return 0;
	}
	for (int i = 1; i <= n; ++i) {
		if (deg[u] != 1) {
			rt = u;
			break;
		}
		if (deg[v] != 1) {
			rt = v;
			break;
		}
	}
	dfs(rt, 0);
	dfs2(rt, 0);
	printf("%lld", ans);
	return 0;
}